/**
 * 
 */
package com.ctn.information.data.retriever.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.ctn.information.data.model.Menu;
import com.ctn.information.data.model.MenuLevel;
import com.ctn.information.data.retriever.Retriever;
import com.ctn.information.data.retriever.Interface.MenuRetriever;
import com.ctn.information.exception.MethodNotSupportException;
import com.ctn.information.util.JsonUtil;


/**
 * Sample Implementation for test only
 * @author Zale
 *
 */
public class MenuRetrieverImpl implements MenuRetriever{



	@Override
	public Menu getById(Long id) throws MethodNotSupportException {
		throw new MethodNotSupportException("Not support");
	}

	@Override
	public List<Menu> getAll(boolean asc) throws MethodNotSupportException {
		throw new MethodNotSupportException("Not support");
	}

	@Override
	public List<Menu> getMenuByLevel(MenuLevel level,Long id) throws JSONException, Exception {
		String url = null;
		if(MenuLevel.ONE.equals(level)){
			url = Retriever.URL_ONE_MENU;
		}else{
			url = Retriever.URL_SEC_MENU+"?id="+id;
		}
		JSONObject jsonObj = JsonUtil.getJSON(url);
		List<Menu> menus = new ArrayList<Menu>();
		JsonUtil.convertJsonToObj(menus, jsonObj);
		return menus;
	}

	@Override
	public List<Menu> getSubMenuFromCache(MenuLevel level) throws MethodNotSupportException {
		throw new MethodNotSupportException("Not support for current");
	}

}
